import 'package:uuid/uuid.dart';

class BleUtils {
  static BleUtils? _instance;

  BleUtils._();

  static BleUtils get instance => _instance ??= BleUtils._();

  String decimalsToHex(List<int> decimals) {
    return decimals.map((decimal) => decimal.toRadixString(16)).join(' ');
  }

  String intToHex(int decimals) {
    return decimals.toRadixString(16);
  }

  //获取二进制指定位置下的对应值
  //true 表示1
  //false 表示0
  bool intToBinary(int value, int index) {
    var radixString = value.toRadixString(2);
    if (index >= 0 && index < radixString.length) {
      return radixString[index] == '1';
    }
    return false;
  }

  //生成一个随机UUID
  String uuidString() {
    return Uuid().v7();
  }

  List<int> uuidList() {
    var uuid = uuidString().replaceAll("-", "");
    // 两两分割十六进制字符串
    List<int> hexPairs = [];
    for (int i = 0; i < uuid.length; i += 2) {
      String pair = uuid.substring(i, i + 2);
      hexPairs.add(int.parse(pair, radix: 16));
    }
    return hexPairs;
  }
}
